<?php

namespace App\Http\Repository;

use App\FriendlyLink;

class FriendlyLinkRepository
{
    private $friendlyLink;

    public function __construct(FriendlyLink $friendlyLink)
    {
        $this->friendlyLink = $friendlyLink;
    }

    //得到友情链接列表
    public function getFriendlyLink()
    {
        $friendlyLink = $this->friendlyLink->join('admins', 'admins.id', '=', 'friendly_links.author')
            ->select('friendly_links.*', 'admins.name as author', 'images.path as image')
            ->leftjoin('images', 'images.id', '=', 'friendly_links.image')
            ->orderBy('friendly_links.xindex', 'DESC')
            ->get();

        return $friendlyLink;
    }

    //得到可展示的友情链接列表
    public function getFriendlyLinkCanShow()
    {
        $friendlyLink = $this->friendlyLink
            ->leftjoin('images', 'images.id', '=', 'friendly_links.image')
            ->select('friendly_links.*', 'images.path as image')
            ->where('friendly_links.status', 1)
            ->orderBy('xindex', 'DESC')
            ->get()
            ->toArray();

        return $friendlyLink;
    }
}